package cd.safe.school.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cd.safe.school.R;
import cd.safe.school.util.ListItemData;

public class CustomizedAdapter extends ArrayAdapter<ListItemData>

{

	private LayoutInflater inflater;

	private Context ctx;

	public static List<ListItemData> list;

	public CustomizedAdapter(Context ctx, List<ListItemData> list)

	{

		super(ctx, R.layout.detail_item, list);

		this.ctx = ctx;

		this.list = list;

		inflater = (LayoutInflater) ctx
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public int getCount()

	{

		return list.size();

	}

	public ListItemData getItem(int position) {

		return list.get(position);
	}

	public long getItemId(int position)

	{

		return position;

	}

	public View getView(int position, View convertView, ViewGroup parent) {

		final int pos = position;

		View rowView = (View) convertView;

		if (rowView == null)

		{

			rowView = (View) inflater.inflate(R.layout.detail_item, null, true);

		}

		TextView tv = (TextView) rowView.findViewById(R.id.student_name);

		tv.setText(list.get(pos).getDeptname());

		CheckBox chkbox = (CheckBox) rowView.findViewById(R.id.student_search);

		chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()

		{

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {

				list.get(pos).setSelected(isChecked);
			}

		});

		chkbox.setChecked(list.get(pos).isSelected());

		return rowView;

	}
}
